﻿Chenxin.UI.ShowListNotLitigation = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListNotLitigation.ashx',
    createSearch: function() {
        return new Chenxin.UI.ShowListNotLitigationSearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=search',
            id: 'NotListLitigation_table',
            renderTo: 'NotListLitigation_table',
            modelId:'RecordId',
            hasCheckBox: false,
            cellBorder: true,
            height: 400,
            pageSize:50,
            scope: this,
            columns: {
                RecordId: {
                    create: false,
                    head: 'id'
                },
                HasAttachment: {
                    head: '附件',
                    width: 30,
                    renderer:function(val,c,row){
                        switch (val) {
                            case 1:
						        return '<a title="附件列表" class="btn_viewdetails" r="'+row.RecordId+'" style="cursor:pointer">有</a>';
						        break;
						    default:
						        return "无"
						        break;
						} 
					}
                },
                ContractCode: {
                    head: '成交编号',
                    width: 110
                },
                HouseAddress: {
                    head: '地址',
                    width: 200
                },
                AppDepart: {
                    head: '提交门店',
                    width: 80
                },
                AcceptedDate: {
                    head: '受理时间',
                    width: 71
                },
                Memo: {
                    head: '备注',
                    width: 300
                }
            }
        });
    },
    loadinfo: function() {
        var _this = this;
        if (!this.currentId) {
            alert("请先选择一条记录！");
            return false;
        }
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentInfo = data;
                }
            }
        });
        return true;
    },
    initEvent: function() {
        var _this = this;
        /*************************事件：起始日期得到焦点************************/
        $("#DateFr").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });
        /*************************事件：终止日期得到焦点************************/
        $("#DateTo").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });
        /*************************事件：非诉申请************************/
        $("#aNotLitigation").click(function() {
            _this.NotLitigation();
        });
        /*************************事件：非诉更新************************/
        $("#aUpNotLitigation").click(function() {
            if (_this.currentId == undefined || _this.currentId == "") {
                alert("请先选择一条非诉记录！");
                return;
            }
            _this.loadinfo();
            _this.UpNotLitigation();
        });
        /*************************事件：详情查看************************/
        $("#aShowDetail").click(function(){
            //详情查看复显示
            if (_this.currentId == undefined || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            Chenxin.Fn.checkPermit(_this.actionUrl,'showdetialnotlitigation',function(data,msg){
			    if(data.permit!=undefined){
				    _this.permit=data.permit;	
				    _this.msg = msg;
			    }
		    },this,{ modelid: _this.currentId });
		    if(_this.permit){			
                window.open("/page/NotLitigationInfo/ShowDetailNotLitagation.aspx?recordid="+_this.currentId+"");
		    }else{
			    alert(_this.msg);
		    }
        });
        /*************************事件：附件列表************************/
        $('.btn_viewdetails').live('click',function(){
            _this.AttachList($(this).attr('r'));
        });
        /*************************事件：上传附件************************/
        $("#aUpload").click(function(){
            if (_this.currentId == undefined || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.uploadAttachment();
        });
    },
    /**
    *非诉申请
    */
    NotLitigation: function() {
        var _this = this;
        if (!this.NotLitigationForm) {
            this.NotLitigationForm = new Chenxin.UI.NotLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '非诉申请',
                op: 'nolitigation',
                afterGetFormJson: function(json) {
                    if(json.ContractCode == undefined || json.ContractCode == "")
                    {
                        delete json.ContractCode;
                    }
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.NotLitigationForm.show()) {
            this.NotLitigationForm.reset();
        }
    },
    /**
    *非诉更新
    */
    UpNotLitigation: function() {
        var _this = this;
        if (!this.NotLitigationForm) {
            this.NotLitigationForm = new Chenxin.UI.NotLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '非诉更新',
                op: 'upnolitigation',
                afterGetFormJson: function(json) {
                    if(json.ContractCode == undefined || json.ContractCode == "")
                    {
                        delete json.ContractCode;
                    }
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.NotLitigationForm.show()) {
            var _data = this.currentInfo;
            this.NotLitigationForm.fitData(_data);
            this.NotLitigationForm.setTitle('非诉更新');
        }
    },
    /**
    *附件列表
    */
    AttachList: function(relationId) {
        if(!this.detailsWin){
			this.detailsWin=new Chenxin.UI.AttachListWin({
				id:'x_details_win',
				title:'附件列表',
				actionUrl:this.actionUrl+'?op=showattachnotlitigation'
			});
		}
		this.detailsWin.show();
		this.detailsWin.grid.param.relationId=relationId;
		this.detailsWin.grid.reload();
    },
    /**
    *附件
    */
    uploadAttachment: function() {
        var _this = this;
        if (!this.UploadNotLitigationForm) {
            this.UploadNotLitigationForm = new Chenxin.UI.UploadNotLitigationForm({
                scrop: this,
                title:'上传附件',
                op:'notlituploadattach',
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.UploadNotLitigationForm.show(this.UploadNotLitigationForm.op, { currentId: _this.currentId })) {
            this.UploadNotLitigationForm.reset();
            this.UploadNotLitigationForm.initUpload(this.currentId);
        }
    },
    initComponent: function() {
        Chenxin.UI.ShowListNotLitigation.superclass.initComponent.call(this);
    }
});

Chenxin.UI.AttachListWin=Chenxin.extend(Chenxin.UI.Win,{
	id:'',
	actionUrl:'',
	width:600,
	hasFoot:true,
	content:'<div id="x_details_grid"></div>',
	createBtn:function(){
		return [{
			text:'关闭',
			handler:this.hide
		}]	
	},
	refreshGrid:function(){
		this.grid.reload();
	},
	createGrid:function(){
		if(this.grid){
			return;
		}
        this.grid=new Chenxin.UI.JsonGrid({
			autoLoad:false,
			actionUrl:this.actionUrl,
            id: 'x_details_grid',
            renderTo: 'x_details_grid',
            hasCheckBox: false,
            modelId: 'relationId',
            scope: this,
			height:230,
			hasTitle:false,
			columns:{
				FileName:{head:'文件名',width:120,sortable:true},
				Remark:{head:'附件说明',width:200,sortable:true},
				DepartName:{head:'上传部门',width:70,sortable:true},
				UserName:{head:'上传人',width:70,sortable:true},
				AddTime:{head:'上传时间',width:70,sortable:true}
			}
		});
	},
//    createGrid: function() {
//		return new Chenxin.UI.ExpandGrid({
//            actionUrl: this.actionUrl,
//            id: 'x_details_grid',
//            renderTo: 'x_details_grid',
//			hasCheckBox:false,
//			cellBorder:true,
//			scope:this,
//			columns:{
//				RelationId:{
//					create:false,
//					head:'id'
//				},
//				FileName:{
//					width:100,
//					head:'文件名'
//				},
//				Remark:{
//					width:100,
//					head:'附件说明'
//				},
//				DepartName:{
//					width:70,
//					head:'上传部门'
//				},
//				UserName:{
//					width:70,
//					head:'上传人'
//				},
//				AddTime:{
//					width:70,
//					head:'上传时间'
//				},
//				Attach:{
//					width:70,
//					head:'附件下载'
//				}
//			}
//		});
//    },
	initComponent:function(){
		Chenxin.UI.AttachListWin.superclass.initComponent.call(this);
		this.createGrid();
	}
});

/**
*查询面板
*/
Chenxin.UI.ShowListNotLitigationSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id:'NotLitigation_search',
    initEvent:function(){
        var _this=this; 
        //查询按钮
        $('#btSreachNotLit').click(function(){
            _this.scope.searchGrid();
        });
        $('#HouseAddress').defText({
            deftxt: '输入物业地址'
        });
        $('#DateFr').defText({
            deftxt: '请选择下发时间'
        });
        $('#DateTo').defText({
            deftxt: '请选择下发时间'
        });
    },
    createComboList: function() {
        //五级联Combo
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.ShowListNotLitigationSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    var showlistnotlitigation = new Chenxin.UI.ShowListNotLitigation();
});